import { trafficPeriodMonitoring, CallVolumeStatistics } from '@/utils/modules/home.js'
self.onmessage = function(event) {
    const { action, interval } = event.data
    if (action === 'start') {
        // 初始化先获取一次数据然后开启定时器
        fetchData()
        // 开始定时任务
        self.intervalId = setInterval(() => {
            fetchData()
        }, interval);
    } else if (action === 'stop') {
        // 停止定时任务
        clearInterval(self.intervalId)
    }
};

function fetchData() {
    Promise.all([trafficPeriodMonitoring(),CallVolumeStatistics()]).then(([trafficPeriod,callVolume]) => {
        console.log('trafficPeriod---------------result', trafficPeriod)
        console.log('callVolume---------------result', callVolume)
        self.postMessage({ type: 'data', payload: [trafficPeriod.data, callVolume.data] });
    }).catch(error => {
        console.log('error', error)
        self.postMessage({ type: 'error', payload: error.message });
        // 停止定时任务
        clearInterval(self.intervalId)
    })
}